<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/Css/agent/default.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/Css/agent/hui.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/Css/agent/hui.admin.css" />
<link rel="stylesheet" href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui.min.css">
<link rel="stylesheet" href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui-append.min.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/Css/agent/public2.css">

<title>代理管理平台</title>
<meta name="keywords" content="炸金花">
<meta name="description" content="炸金花">
</head>
<body>
<div class="page-container">
    	<div class="tableDiv table-border radius box-shadow"> 
            <div class="tableCon">
            <div class="tableDiv table-border radius box-shadow">
			<div class="tableNav">基本信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a herf="#" id="editPassword"><font size="3px">修改密码</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="a1" href="<%=request.getContextPath()%>/agent/logout.html"><font size="3px">退出</font></a></div>
			<div class="tableCon pd-2">
				<div class="sui-row tableRow">
					<div class="span1 text-c ">用户ID：</div>
					<div class="span1"><font id="userId"></font></div>
				</div>
				<div class="line dashBorder"></div>
				<div class="sui-row tableRow">
					<div class="span1 text-c ">剩余钻石：</div>
					<div class="span1"><font id="totalCoin"></font></div>
				</div>
			</div>
		</div>
		<div class="sui-row tableRow">
			<div class="span3 text-c">  
              <div> <a href="javascript:void(0);" class="sui-btn btn-block btn-xlarge btn-success btn-left btn-width40" id="sell">出售</a></div>
              <div><a href="javascript:void(0);" class="sui-btn btn-block btn-xlarge btn-success btn-right btn-width40" id="recharge">充值</a></div>
        	</div>
        </div>
        <div id="showSellCoin">
        <div class="tableDiv table-border radius box-shadow">
        	<div class="sui-row tableRow">
				<div class="span3">
                       <input type="text" id="playerId" placeholder="请输玩家ID" class="input-text radius size-M" value="">
	            </div>
    		    <a href="javascript:void(0);" class="sui-btn btn-block btn-xlarge btn-success btn-right btn-width20 btn-margin8" id="searchPlayer">搜索玩家</a>
        	</div>
        	<div class="line dashBorder"></div>
        	<%--<div class="span3">玩家ID：<font id="playerIdTxt"></font></div>--%>
        	<div class="span3">昵称：<font id="playerNickTxt"></font></div>
        	<div class="span3">玩家余额：<font id="playerCoinTxt"></font></div>
		</div>
		<div class="line dashBorder"></div>
		<div class="tableDiv table-border radius box-shadow">
	        	<div class="sui-row tableRow">
					<div class="span3" style="display:inline">
						<input type="text" id="sellCoinCount" placeholder="出售钻石数量" class="input-text radius size-M" value="">
					</div>
					<div  class="span3" style="display:inline">
						<input type="text" id="sellAmountCount" placeholder="金额" class="input-text radius size-M" value="">
		            </div>
	    		    <a href="javascript:void(0);" class="sui-btn btn-block btn-xlarge btn-success btn-right btn-width20 btn-margin8" id="sellCoinBtn">出售</a>
	        	</div>
	        	<div class="line dashBorder"></div>
	        	
	        	
	        	
	        	<div class="tableDiv table-border radius box-shadow mt-30">
					<form id="queryForm" class="form-inline definewidth m20" action="/" method="post">
						<%--<p>
							<label> <span>玩家ID: </span>
								<input type="text" name="playerIdSearch" id="playerIdSearch" class="abc input-default"
									   value="${sourceType}">&nbsp;&nbsp;
							</label>
						</p>--%>
						<p>
							<label> <span>订单来源: </span>
								<select name="sourceType" id="sourceType" class="abc input-default">
									<option value="-1">-----全部来源-----</option>
									<option value="1">平台充值</option>
									<option value="0">手机充值</option>

								</select>
							</label>

							<label> <span>时间区间:
			               </span><input class="text-input small-input" type="text" id="begintime"
									  name="begintime" value="${paramMap.begintime}"  onclick="WdatePicker({startDate:'%y-%M-%d'})"
									  onFocus="WdatePicker({startDate:'%y-%M-%d %H:%m:%s',maxDate:'#F{$dp.$D(\'endtime\')}',minDate:'#F{$dp.$D(\'endtime\',{d:-32})}',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"
									  readonly="readonly" />~~~

								<input class="text-input small-input"
									   type="text" id="endtime" name="endtime" value="${paramMap.endtime}" onclick="WdatePicker({startDate:'%y-%M-{%d+1}'})"
									   onFocus="WdatePicker({startDate:'%y-%M-%d %H:%m:%s',maxDate:'#F{$dp.$D(\'begintime\',{d:+32})}',minDate:'#F{$dp.$D(\'begintime\')}',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"
									   readonly="readonly" />
							</label>
							<button type="button" class="btn btn-primary" id="searchOrder"  onclick="searchSomething()"  >查询</button>
						</p>
					</form>
						<div  class="tableNav nopadding">
							<div class="tableDiv table-border radius box-shadow">

								<div class="span3">商城今日收入：<font id="orderDayTxt"></font></div>
								<div class="span3">商城本周收入：<font id="orderWeekTxt"></font></div>
								<div class="span3">商城总收入：<font id="orderAllTxt"></font></div>
								<div class="span3">平台今日收入：<font id="platDayTxt"></font></div>
								<div class="span3">平台本周收入：<font id="platWeekTxt"></font></div>
								<div class="span3">平台总收入：<font id="platAllTxt"></font></div>
							</div>
							<table class="sui-table table-bordered nomargin">
								<thead>
									<tr>
										<th width="20%">玩家ID</th>
										<th width="10%">消费金额</th>
										<th width="10%">钻石数量</th>
										<th width="10%">订单状态</th>
										<th width="20%">订单时间</th>
										<th width="20%">代理商ID</th>
										<th width="10%">订单来源</th>

									</tr>
								</thead>
								<tbody id="sellListTab">
								</tbody>
								<tfoot>
								<tr bgcolor="EEF7FE">
									<td colspan="14" bgcolor="EEF7FE" class="f">
										<div align="right" style="bgcolor:EEF7FE" class="f" id="pageDiv">
											<%--<jsp:include page="/common/pageUtil.jsp"></jsp:include>--%>
										</div>
									</td>
								</tr>
								</tfoot>
							</table>
						</div>


	            </div>
		 </div>
        </div> 
    </div>
        
<script type="text/javascript" src="http://g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script> 
<script type="text/javascript" src="<%=request.getContextPath()%>/js/lib/hui.js"></script> 
<script type="text/javascript" src="<%=request.getContextPath()%>/js/lib/hui.admin.js"></script> 
<script type="text/javascript" src="http://g.alicdn.com/sj/dpl/1.5.1/js/sui.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/lib/jquery.slimscroll.min.js"></script> 
<script type="text/javascript" src="<%=request.getContextPath()%>/js/public.js"></script>
			<script type="text/javascript"	src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"></script>
</body>
<script type="text/javascript">
	var path="/card-manager";

	$(function(){
		$(document).ready(function(){
			$("#showSellCoin").show();
			$("#showMoney").hide();
//		userId
			$.ajax({
				type: "POST",
				url: path+"/manager/agentQueryCurrentInfo.html",
				dataType: 'json',
				contentType:'application/json',
				data: JSON.stringify({
				}),
				success: function(json) {
					if(json.errorCode==undefined){
						return;
					}else if(json.errorCode>0){
						alertMsgs(json.errorMsg);
						return;
					}
					var obj = json.managerInfo;
					$("#userId").html(obj.id);
					$("#totalCoin").html(obj.agentCoin);

				},
				error: function(err) {
					alertMsgs(err);
				}
			});
			showHistoryRefresh();
		});

		$(document).on("click", "#searchPlayer", function(e){
			var playerId = $("#playerId").val();
			if(playerId==""||playerId==undefined||playerId==null){
				alertMsgs("请输入玩家id");
				return;
			}
			$.ajax({
				type: "POST",
				url: path+ "/player/agentQueryPlayInfoById.html",
				dataType: 'json',
				contentType:'application/json',
				data: JSON.stringify({
					"playerId":playerId
				}),
				success: function(json) {
					if(json.errorCode==undefined){
						return;
					}else if(json.errorCode>0){
						alertMsgs(json.errorMsg);
						return;
					}
					var playerInfo = json.playerInfo;

					$("#playerIdTxt").html(playerInfo.id);
					$("#playerNickTxt").html(playerInfo.nickName);
					$("#playerCoinTxt").html(playerInfo.diamond);

				},
				error: function(err) {
					alertMsgs(err);
				}
			});
		});

		$(document).on("click", "#sellCoinBtn", function(e){
			var playerId = $("#playerId").val();
			if(playerId==""||playerId==undefined||playerId==null){
				alertMsgs("请输入玩家id");
				return;
			}
			var coin = $("#sellCoinCount").val();
			if(validate(coin)){
				return;
			}
			var amount = $("#sellAmountCount").val();
			if(validateFloat(amount)){
				return;
			}


			$.ajax({
				type: "POST",
				url: path+ "/manager/agentSellCoin.html",
				dataType: 'json',
				contentType:'application/json',
				data: JSON.stringify({
					"playerId":playerId,
					"coin":coin,
					"amount":amount
				}),
				success: function(json) {

					if(json.errorCode==undefined){
						return;
					}else if(json.errorCode>0){
						alertMsgs(json.errorMsg);
						return;
					}

					alertMsgs(json.result);
					//window.location.reload();
					$("#totalCoin").html(json.managerCoin);
					$("#playerCoinTxt").html(json.playerCoin);
					showHistoryRefresh();
				},
				error: function(err) {
					alertMsgs(json.errorMsg);
				}
			});
		});

		/*$(document).on("click", "#searchOrder", function(e) {

			showHistoryRefresh()
		});
*/
		function showHistoryRefresh(page){

			var strHtml;
			$("#sellListTab").html("");
			$("#pageDiv").html("");
			$.ajax({
				type: "POST",
				url: path+"/agent/order/queryOrder.html",
				dataType: 'json',
				data: {
					"pageIndex":page,
					"begintime":$("#begintime").val(),
					"endtime":$("#endtime").val(),
					"playerIdSearch":$("#playerIdSearch").val(),
					"sourceType":$('#sourceType option:selected') .val()
				},

				success: function(json) {
					if(json.errorCode==undefined){
						return;
					}else if(json.errorCode>0){
						alertMsgs(json.errorMsg);
						return;
					}
					$("#orderDayTxt").html(json.dayOrderIncome);
					$("#orderWeekTxt").html(json.weekOrderIncome);
					$("#orderAllTxt").html(json.allOrderIncome);
					$("#platDayTxt").html(json.dayPlatIncome);
					$("#platWeekTxt").html(json.weekPlatIncome);
					$("#platAllTxt").html(json.allPlatIncome);


					var page = json.page;
                    var list=page.data;
					$.each(list, function(index, element) {
						var status="";
						var sourceType="";
						if(element.orderStatus==0){
							status="未支付"
						}else if(element.orderStatus==1){
							status="已支付"
						}else{
							status="交易取消"
						}

						if(element.sourceType==1){
							sourceType="平台充值"
						}else if(element.sourceType==0){
							sourceType="手机充值"
						}
						strHtml=strHtml+'<tr><td >'+element.playerId+'</td>'+
								'<td>'+element.money.toFixed(2)+'</td>'+
								'<td >'+element.coin+'</td>'+
								'<td >'+status+'</td>'+
								'<td >'+element.orderTime+'</td>'+
								'<td >'+element.agentId+'</td>'+
								'<td >'+sourceType+'</td></tr>';
					});

					$("#sellListTab").html(strHtml);



					var showStr=""
					if(page.currentPage>1){
						showStr+="<a href=\"javascript:getNextPage('"+(page.currentPage -1)+"')\" class=\"textlink\">上一页</a>";
					}
					if(page.currentPage==1){

						showStr+="上一页";
					}
					if(page.currentPage<page.maxPage) {
						showStr += "<a href=\"javascript:getNextPage('" + (page.currentPage + 1) + "')\" >下一页</a>";
					}
					if(page.currentPage== page.maxPage){
						showStr+="下一页";
					}
					var pubStr="当前第 "+page.currentPage+"页	共"+page.maxPage+"页 共"+page.totalCount+"条 转到第 <input type=\"text\" name=\"goPage\" id=\"goPage\"value=\"\" size=3> 页"
								+"<input type=\"button\" value=\"Go\" onclick=\"javascript:changePage(goPage.value,''+page.maxPage+'')>";

					$("#pageDiv").html(showStr+pubStr);

					},
				error: function(err) {
					alertMsgs(err.errorMsg);
				}
			});
		}






		var wWidth = $(window).width();
		var dWidth = parseInt( wWidth - 100  );
		$("#editPassword").click(function(){
			var updateStr='<div class="page-container">  <div class="tableCon"> <div class="sui-row tableRow nopadding"> <div class="span2 text-r"> 新密码： </div> <div class="span3"> <input id="newPassword" type="text" placeholder="请输入新密码" class="input-text radius size-M" value=""> </div>  </div> <div class="sui-row tableRow nopadding"> <div class="span2 text-r"> 确认密码： </div> <div class="span3"> <input id="passwordSecond" type="text" placeholder="请输入密码" class="input-text radius size-M" value=""> </div>  </div> <div class="sui-row tableRow"> <div class="span3 text-r"> <a href="javascript:void(0);" class="sui-btn btn-xlarge btn-success" id="saveBtn">保存</a> <a href="javascript:void(0);" class="sui-btn btn-xlarge btn-primary" id="resetBtn">重置</a></div></div>  </div> </div>';
			//$('#detailModal').modal('shadeIn');
			$.alert({
				id:'updateModal',
				backdrop: true,//  决定是否为模态对话框添加一个背景遮罩层。另外，该属性指定static时，表示添加遮罩层，同时点击模态对话框的外部区域不会将其关闭。
				bgcolor: '#000',//   背景遮罩层颜色，默认是黑色。可以用rgba设置透明度
				keyboard: false,//   是否可由esc按键关闭
				title: '修改密码',
				body: updateStr,
				backdrop:false,
				closeBtn: true,   //是否显示右上角叉叉（html使用方式无需配置，直接改html结构即可））
				hasfoot: false,  //是否显示脚部  默认true
				width: dWidth,
				//height:mHeight,
				show:function(e){ },
				shown:function(e){},
				hide:function(e){
					//$('#detailModal').modal('shadeOut');
				}
			})
		});
		$(document).on("click", "#resetBtn", function(e) {
			$("#newPassword").val("");
			$("#passwordSecond").val("");
		});

		$(document).on("click", "#saveBtn", function(e) {
			var newPassword = $("#newPassword").val();
			var passwordSecond = $("#passwordSecond").val();
			if(newPassword!=passwordSecond){
				alertMsgs("密码不一致");
				return;
			}
			$.ajax({
				type: "POST",
				url: path+"/agent/changePwd.html",
				dataType: 'json',
				contentType:'application/json',
				data: JSON.stringify({
					"newPassword":newPassword
				}),
				success: function(json) {
					if(json.errorCode==undefined){
						return;
					}else if(json.errorCode>0){
						alertMsgs(json.errorMessage);
						return;
					}
					alertMsgs("修改成功");
				},
				error: function(err) {
					alertMsgs(err.responseText);
				}
			});
		});
	})

	function getNextPage(page){
		var strHtml;
		$("#sellListTab").html("");
		$("#pageDiv").html("");
		$.ajax({
			type: "POST",
			url: path+"/agent/order/queryOrder.html",
			dataType: 'json',
			data: {
				"pageIndex":page,
				"playerIdSearch":$("#playerIdSearch").val(),
				"sourceType":$('#sourceType option:selected') .val()
			},
			success: function(json) {
				if(json.errorCode==undefined){
					return;
				}else if(json.errorCode>0){
					alertMsgs(json.errorMsg);
					return;
				}
				var page = json.page;
				var list=page.data;
				$.each(list, function(index, element) {
					var status="";
					var sourceType="";
					if(element.orderStatus==0){
						status="未支付"
					}else if(element.orderStatus==1){
						status="已支付"
					}else{
						status="交易取消"
					}

					if(element.sourceType==1){
						sourceType="平台充值"
					}else if(element.sourceType==0){
						sourceType="手机充值"
					}
					strHtml=strHtml+'<tr><td >'+element.playerId+'</td>'+
							'<td>'+element.money.toFixed(2)+'</td>'+
							'<td >'+element.coin+'</td>'+
							'<td >'+status+'</td>'+
							'<td >'+element.orderTime+'</td>'+
							'<td >'+element.agentId+'</td>'+
							'<td >'+sourceType+'</td></tr>';
				});

				$("#sellListTab").html(strHtml);


				var showStr=""
				if(page.currentPage>1){
					showStr+="<a href=\"javascript:getNextPage('"+(page.currentPage -1)+"')\" class=\"textlink\">上一页</a>";
				}
				if(page.currentPage==1){

					showStr+="上一页";
				}
				if(page.currentPage<page.maxPage) {
					showStr += "<a href=\"javascript:getNextPage('" + (page.currentPage + 1) + "')\" >下一页</a>";
				}
				if(page.currentPage== page.maxPage){
					showStr+="下一页";
				}
				var pubStr="当前第 "+page.currentPage+"页	共"+page.maxPage+"页 共"+page.totalCount+"条 转到第 <input type=\"text\" name=\"goPage\" id=\"goPage\"value=\"\" size=3> 页"
						+"<input type=\"button\" value=\"Go\" onclick=\"javascript:changePage(goPage.value,''+page.maxPage+'')>";

				$("#pageDiv").html(showStr+pubStr);

			},
			error: function(err) {
				alertMsgs(json.errorMsg);
			}
		});
	}


	function searchSomething(){

		if($("#begintime").val()==''||$("#endtime").val()==''){
			alert("请选择开始或者结束时间");
			return ;
		}
		var strHtml;
		$("#sellListTab").html("");
		$("#pageDiv").html("");
		$.ajax({
			type: "POST",
			url: path+"/agent/order/queryOrder.html",
			dataType: 'json',
			data: {
				"pageIndex":page.currentPage,
				"begintime":$("#begintime").val(),
				"endtime":$("#endtime").val(),
				"playerIdSearch":$("#playerIdSearch").val(),
				"sourceType":$('#sourceType option:selected') .val()
			},

			success: function(json) {
				if(json.errorCode==undefined){
					return;
				}else if(json.errorCode>0){
					alertMsgs(json.errorMsg);
					return;
				}
				$("#orderDayTxt").html(json.dayOrderIncome);
				$("#orderWeekTxt").html(json.weekOrderIncome);
				$("#orderAllTxt").html(json.allOrderIncome);
				$("#platDayTxt").html(json.dayPlatIncome);
				$("#platWeekTxt").html(json.weekPlatIncome);
				$("#platAllTxt").html(json.allPlatIncome);


				var page = json.page;
				var list=page.data;
				$.each(list, function(index, element) {
					var status="";
					var sourceType="";
					if(element.orderStatus==0){
						status="未支付"
					}else if(element.orderStatus==1){
						status="已支付"
					}else{
						status="交易取消"
					}

					if(element.sourceType==1){
						sourceType="平台充值"
					}else if(element.sourceType==0){
						sourceType="手机充值"
					}
					strHtml=strHtml+'<tr><td >'+element.playerId+'</td>'+
							'<td>'+element.money.toFixed(2)+'</td>'+
							'<td >'+element.coin+'</td>'+
							'<td >'+status+'</td>'+
							'<td >'+element.orderTime+'</td>'+
							'<td >'+element.agentId+'</td>'+
							'<td >'+sourceType+'</td></tr>';
				});

				$("#sellListTab").html(strHtml);



				var showStr=""
				if(page.currentPage>1){
					showStr+="<a href=\"javascript:getNextPage('"+(page.currentPage -1)+"')\" class=\"textlink\">上一页</a>";
				}
				if(page.currentPage==1){

					showStr+="上一页";
				}
				if(page.currentPage<page.maxPage) {
					showStr += "<a href=\"javascript:getNextPage('" + (page.currentPage + 1) + "')\" >下一页</a>";
				}
				if(page.currentPage== page.maxPage){
					showStr+="下一页";
				}
				var pubStr="当前第 "+page.currentPage+"页	共"+page.maxPage+"页 共"+page.totalCount+"条 转到第 <input type=\"text\" name=\"goPage\" id=\"goPage\"value=\"\" size=3> 页"
						+"<input type=\"button\" value=\"Go\" onclick=\"javascript:changePage(goPage.value,''+page.maxPage+'')>";

				$("#pageDiv").html(showStr+pubStr);

			},
			error: function(err) {
				alertMsgs(err.errorMsg);
			}
		});


	}


	function changePage(pageindex,maxpage){

		if(isNumber(pageindex)){
			if(parseInt(pageindex) > parseInt(maxpage)){
				pageindex = maxpage;
			}
			if(pageindex==""){
				pageindex = 1;
			}
			if(pageindex==0){
				pageindex = 1
			}
			getNextPage(pageindex);
		}else{
			alert("请输入数字");
		}
	}
	function isNumber(oNum){
		if(oNum.indexOf(".")==1){
			return false;
			alert("请输入整数");
		};
		if(!oNum) return false;
		var strP=/^\d+(\.\d+)?$/;
		if(!strP.test(oNum)) return false;
		try{
			if(parseFloat(oNum)!=oNum) return false;
		}
		catch(ex)
		{
			return false;
		}
		return true;
	}

	function validateFloat(obj){

		var reg1 = new RegExp("^[0-9]+$");
		var reg = new RegExp("^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$");
		if(!reg.test(obj)&&	!reg1.test(obj)){
			alert("请输入有效数字!");
			return true;
		}
		return false;
	}


	function validate(obj){
		var reg = new RegExp("^-?\\d+$");
		debugger;
		if(!reg.test(obj)){
			alert("请输入数字!");
			return true;
		}
		if(obj<0){
			alert("请输入大于0的整数");
			return true;
		}
		return false;
}
</script>
</html>